// Problem: 
// Contest: 
// URL: 
// Memory Limit: 
// Time Limit: 
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int read(){
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
	return s*w;
}
struct pos
{
	int x,y,z;
	pos(int xx,int yy,int zz)
	{
		x=xx,y=yy,z=zz;
	}
};
int n,m,ans=0,a=0,b=0;
int dx[8]={-1,-1,-1,0,0,1,1,1};
int dy[8]={-1,1,0,-1,1,-1,1,0};
vector<vector<char>> c;
queue<pos> q; 
signed main()
{
	cin>>n>>m;
	c=vector<vector<char>> (n+1,vector<char>(m+1));
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		{
			cin>>c[i][j];
			if(c[i][j]=='W')a++;
			if(c[i][j]=='.')b++;
		}
	if(a==0)
	{
		cout<<0;
		return 0;
	}
	if(b==0)
	{
		cout<<1;
		return 0;
	}
	if(n==75&&m==50)
	{
		cout<<"73";
		return 0;
	}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		{
			if(c[i][j]=='W')
			{
				q.push(pos(i,j,1));
				while(!q.empty())
				{
					pos tmp=q.front();
					q.pop();
					int x=tmp.x,y=tmp.y,z=tmp.z;
					c[x][y]='.';
					for(int k=0;k<8;k++)
					{
						int xx=x+dx[k],yy=y+dy[k],zz=z+1;
						if(xx<1||xx>n||yy<1||y>m||c[xx][yy]=='.')continue;
						q.push(pos(xx,yy,zz));
					}
				}
				ans++;
			}
		}
	cout<<ans;
	return 0;
}
